package com.ccit.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ccit.common.result.Result;
import com.ccit.model.Admin;
import com.ccit.model.vo.admin.AdminUpdateVo;
import com.ccit.user.service.AdminService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/InwardAdmin")
public class InwardAdminController {
    @Autowired
    private AdminService adminService;

    @ApiOperation(value = "根据名称逻辑删除管理员")
    @DeleteMapping("/remove/{name}")
    public Result removeAdminById(@PathVariable("name") String name) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("name", name);
        boolean flag = adminService.remove(wrapper);
        if (flag) {
            return Result.ok("删除成功");
        } else {
            return Result.fail().message("删除失败");
        }
    }

    @ApiOperation(value = "修改员工信息的同时修改管理员信息")
    @PutMapping("/updateInfo")
    public boolean updateAdminInfoByEmployee(@RequestBody AdminUpdateVo adminUpdateVo) {
        System.out.println(adminUpdateVo.toString());
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("phone", adminUpdateVo.getPhone());
        Admin admin = adminService.getOne(queryWrapper);
        System.out.println(admin+"------------------------");
        System.out.println(adminUpdateVo+"======================");
        admin.setName(adminUpdateVo.getNewName());
        admin.setPhone(adminUpdateVo.getNewPhone());
        boolean result = adminService.updateById(admin);
        return result;
    }

}
